<?php

class log
{
	static $log=array();
	static $path='data/log/';
	static $macSize='1024';
	static $format='c';

	static function record($message,$level=1){
		if($message)
		{
			self::$log[]="{$level}: {$message}\r\n";;
		}
	}

	static function save()
	{
		if(empty(self::$log))return false;
		if(empty($destination))
		$destination = self::$path.date('y_m_d').'.log';
		//检测日志文件大小，超过配置大小则备份日志文件重新生成
		if(is_file($destination) && floor(self::$macSize) <= filesize($destination) )
		rename($destination,dirname($destination).'/'.time().'-'.basename($destination));
		
		$now = date(self::$format);
		$message=$now.' '.get_client_ip().' '.$_SERVER['REQUEST_URI']."\r\n".implode('',self::$log)."\r\n";
		error_log($message, 3,$destination);
		self::$log=array();
	}

	static function write($arr,$level=1)
	{
		if(empty($destination))
		$destination = self::$path.date('y_m_d').'.log';
		//检测日志文件大小，超过配置大小则备份日志文件重新生成
		if(is_file($destination) && floor(self::$macSize) <= filesize($destination) )
		rename($destination,dirname($destination).'/'.time().'-'.basename($destination));
		error_log("{$now} {$level}: {$message}\r\n", 3,$destination,$extra );
	}

}
?>